import React from 'react';
import { Select, AutoComplete } from 'antd';

const { Option } = Select;

const getSelectOptions = props => {
    // customRender 可以自定义渲染 Option
    const { options, customRender } = props;
    if (options) {
        return options.map(item => {
            if (customRender) {
                return customRender(props, item);
            }
            return (
                <Option key={item.key} value={item.key}>
                    {item.label}
                </Option>
            );
        });
    }
    return null;
};
const getAutoCompleteOptions = props => {
    const { options, customRender } = props;
    if (options) {
        return options.map(item => {
            if (customRender) {
                return customRender(props, item);
            }
            return (
                <AutoComplete.Option key={item.key} label={item.label}>
                    {item.label}
                </AutoComplete.Option>
            );
        });
    }
    return null;
};

export default {
    'antd.Select': props => getSelectOptions(props),
    'antd.AutoComplete': props => getAutoCompleteOptions(props),
    'antd.Checkbox': (props, item) => {
        const { name } = item;
        return name;
    }
};
